package com.kelvem.saas.workbanch.core.manager.dao;

import com.kelvem.saas.workbanch.fsm.anno.entity.RegisterDao;
import com.kelvem.saas.workbanch.fsm.dao.BaseDao;
import com.kelvem.saas.workbanch.core.manager.model.MetaTableEntity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

/**
 * 实体表Dao
 *
 * @author kelvem
 * @version 1.0
 */
@Mapper
@RegisterDao(entityClass= MetaTableEntity.class)
@Repository
public interface MetaTableDao extends BaseDao<MetaTableEntity> {
    
    @Select("SELECT t.* FROM meta_table t WHERE t.id=#{id}")
    @Results({
            @Result(column="id",property="id"),
            //这里的column="group_id"是将列值的参数传给GroupMapper的queryGroupByGid方法
            @Result(column="id",property="metaTableColumnList",
                    many=@Many(select="com.kelvem.saas.workbanch.core.manager.dao.MetaTableColumnDao.queryMetaTableColumn",
                            fetchType= FetchType.EAGER)),
            @Result(column="id",property="metaTableActionList",
                    many=@Many(select="com.kelvem.saas.workbanch.core.manager.dao.MetaTableActionDao.queryMetaTableActionList",
                            fetchType= FetchType.EAGER)),
    })
    MetaTableEntity getMetaTableById(@Param("id") Long id);
    
    @Select("/* sql */ ${sql}")
    Integer createMetaTable(@Param("sql") String sql);

    @Select("drop table if exists `${metaTableName}`;")
    Integer dropMetaTable(@Param("metaTableName") String metaTableName);
    
}
